package com.ykt.service;

import com.ykt.common.constant.ParamNames;
import com.ykt.common.utils.page.PageData;
import com.ykt.common.utils.page.PageParam;
import com.ykt.model.Goods;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品服务
 */
public class GoodsService {
    private static final Logger LOGGER = LoggerFactory.getLogger(GoodsService.class);


    private Goods goodsDao = Goods.dao;


    public List<Goods> findByShopId(int shopId){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put(ParamNames.shopId, shopId);
        paramMap.put(ParamNames.status, Goods.Status.IN.name());

        PageParam<Map<String, Object>> param = new PageParam<>();
        param.setPageNo(1);
        param.setPageSize(Integer.MAX_VALUE);
        param.setP(paramMap);

        PageData<Goods> pd = goodsDao.pageFind(param);
        if(pd == null){
            return null;
        }
        return pd.getPageData();
    }

    public PageData<Goods> pageFind(PageParam<Map<String, Object>> param){
        return goodsDao.pageFind(param);
    }

    public PageData<Goods> findGoodsByUpdateTime(PageParam<Integer> param){
        return goodsDao.findGoodsByUpdateTime(param);
    }

    public Goods findByGoodsId(int goodsId){
        return goodsDao.findByGoodsId(goodsId);
    }

    public List<Goods> findRecommends(int bizId, Goods.RecommendType recommType){
        return goodsDao.findRecommends(bizId, recommType.name());
    }
}
